
// 处理初始化模版
import React from 'react';

import {
    promptBox
} from 'nc-lightapp-front';

import language from '../../language';

const formLists = ['bd_psndoc', 'hi_psnjob_h', 'hi_psnorg_h'];
let deleteButton = null;
let editButton = null;

// 初始化处理template数据
export default function processTemplate(template) {

    template['ncc600704list'].items.map((item, index) => {
        // item.width = '120px';
    });

    template['entryinfo'] && template['entryinfo'].items.map((item) => {
        item.queryCondition = {};
    })

    template['ncc600704list'].items.push({
        itemtype: 'customer',
        label: language['hi6007-000029'],/* 国际化处理： 操作*/
        visible: true,
        width: '120px',
        fixed: 'right',
        attrcode: 'operation',
        render: (text, record, index) => {
            if(deleteButton === null) {
                deleteButton = this.state.buttons.filter(item => item.key === 'Delete').length > 0;
            }
            if(editButton === null) {
                editButton = this.state.buttons.filter(item => item.key === 'Edit').length > 0;
            }

            return (
                <div>
                    <If condition={editButton}>
                        <a
                            href="javascript:void(0)"
                            className="operator-btn"
                            onClick={() => {
                                this.setState({
                                    selectedRows: [{ data: record }],
                                    pageFrom : 'modify',
                                    mainPageButtonClick: 'modify'
                                }, () => {
                                    this.toEditPage('modify');
                                });
                            }}
                        >
                            {language['hi6007-000030']}{/* 国际化处理： 修改*/}
                        </a>
                    </If>
                    
                    <If condition={deleteButton}>
                        <a
                            href="javascript:void(0)"
                            className="operator-btn"
                            onClick={() => {
                                this.setState({
                                    // 为了和选中的数据对应上
                                    selectedRows: [{ data: record }]
                                }, () => {
                                    this.deleteMainTableRow();
                                });
                            }}
                        >
                            {language['hi6007-000031']}{/* 国际化处理： 删除*/}
                        </a>
                    </If>
                </div>
            );
        }
    });

    template['gridrelation']['sort'] = {
        destBrowseAreaCode: null,
        destEditAreaCode: null,
        srcAreaCode: 'sort',
        tabRelation: []
    }

    template['bd_psndoc'].items.map((item) => {
        if(item.attrcode === 'photo') {
            item.visible = false
        }
        //uapbd适配，详细地址placeholder，专项，先注掉
        /*else if(item.attrcode === 'addr'){
            item.detailinfoTip = '请详细到小区门牌号';
        }*/
    });
    
    template['hi_psnjob_h'].relationcode = 'bd_psndoc';
    template['hi_psnorg_h'].relationcode = 'bd_psndoc';


    return template
}
